function alterMessage() {
 	return alert("这是客户端js信息");
 }

 function alterMessageOc(obj) {
     return alert(obj);
 }

 function initImgData(obj){
     $.ajax({
            type : "GET",
            url : obj+"/index/queryAll",
            data : "",
            success : function(msg) {
            imgArray = msg.data;
            for (var i = 0; i < msg.data.length; i++) {
             var imgurl = msg.data[i];
             var id = "id_"+i;
             $("#img_id").append("<img id="+id+" alt='鼠标在图上的提示文字' height='200' width='100%' src="+imgurl+" onclick='onImageClick("+i+")' /><br/>"
                                +"<hr width='100%' color=#8A8989 size=10 />");
             }
            }
     });
 }

 function sendObjec() {
     bridgeT.callHandler('ObjC_Echo', {'key':'我是H5按钮触发js来调用oc方法'}, function responseCallback(responseData) {
                         console.log("JS received response:", responseData)
                         alert(responseData);
                       })
 }

var imgArray;

function onImageClick(obj){
    var picUrl = imgArray[obj];
    var allImage = document.querySelectorAll("img[src]");
    allImage = Array.prototype.slice.call(allImage, 0);
    var urls = new Array();
    var index = obj;
    var x = 0;
    var y = 0;
    var width = 0;
    var height = 0;
    allImage.forEach(function(image) {
                     var imgUrl = image.getAttribute("src");
                     var newLength = urls.push(imgUrl);
                     if(imgUrl == picUrl || imgUrl == decodeURIComponent(picUrl)){
                        x = image.getBoundingClientRect().left;
                        y = image.getBoundingClientRect().top;
                        x = x + document.documentElement.scrollLeft;
                        y = y + document.documentElement.scrollTop;
                        width = image.width;
                        height = image.height;
                        console.log("x:"+x +";y:" + y+";width:"+image.width +";height:"+image.height);
                     }
    });

    console.log("检测到点击");

    bridgeT.callHandler('ObjC_Echo', {'index':index,'picUrl':picUrl,'imgArray':imgArray,'x':x,'y':y,'width':width,'height':height}, function responseCallback(responseData) {
                        console.log("JS已经发出imgurl和index:", responseData)
                        //alert("oc回传js数据"+responseData);
                        })
    
}

//--------------------------------初始化-----------------------------------
function setupWebViewJavascriptBridge(callback) {
	if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
	if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
	window.WVJBCallbacks = [callback];
	var WVJBIframe = document.createElement('iframe');
	WVJBIframe.style.display = 'none';
	WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
	document.documentElement.appendChild(WVJBIframe);
	setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}

var bridgeT;

function initJsBridge(){
	setupWebViewJavascriptBridge(function(bridge) {
                             bridgeT = bridge;
                             /* Initialize your app here */
                             bridgeT.registerHandler('JS_Echo', function(data, responseCallback) {
                                                    console.log("JS Echo called with:", data)
                                                        //alterMessageOc(data)
                                                    
                                                        responseCallback(data)
                                                    })
                             });
}
//--------------------------------初始化-----------------------------------